/*
 * @Author: @yzcheng
 * @Date: 2021-04-13 13:56:39
 * @Version: 1.0
 * @LastEditors: @yzcheng
 * @Description:
 * @LastEditTime: 2021-04-15 20:02:11
 */
import { isMicroApp } from '@/utils/micro'
import { setToken } from '@/utils/auth'
// import "@/utils/setRem"

import createApp from './createApp'
import { App } from 'vue'
import 'element-plus/lib/theme-chalk/index.css'
import '@/assets/css/brunetDepartment.scss'
import '@/assets/css/common.scss'
import '@/assets/css/whiteFastens.scss'
import '@/assets/styles/index.scss' // global css
import './public-path'
import 'normalize.css'
import { ObjectType } from 'typings/interfaces'
import './icons/index.ts'
import dayjs from 'dayjs'
// import { handlePermission } from './permission' //权限控制
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
dayjs.extend(isSameOrBefore)
dayjs.extend(isSameOrAfter)
let app: App | null = null
import "swiper/swiper.css"
if (!isMicroApp()) {
  createApp('#app')
  // handlePermission();
}

// 子应用必须暴露加载的生命周期hooks
export async function bootstrap(): Promise<void> {
  console.log('[vue] vue app bootstraped')
}

export async function mount(props: ObjectType): Promise<void> {
  const { token, container, onGlobalStateChange, setGlobalState, lang, className, user } = props
  app = await createApp(
    container.querySelector('#app'),
    {
      setGlobalState,
      onGlobalStateChange,
    },
    lang
  )
  setToken(token)
  localStorage.setItem('className', className)
}

export async function unmount(): Promise<void> {
  app?.unmount('#app')
}
